<script src="<?php echo base_url();?>script/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="<?php echo base_url()?>script/jquery.validationEngine-en.js"></script>
<link href="<?php echo base_url()?>/style/validationEngine.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="<?php echo base_url()?>script/jquery.validationEngine.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>style/jquery.notifyBar.css" media="screen" />
<script src="<?php echo base_url();?>script/jquery.notifyBar.js" type="text/javascript"></script>
<?php if (isset($addSuccess) && $addSuccess) { ?>
<script type="text/javascript">
    $.notifyBar({
        html: "You have successfully added new representative",
        cls: "success",
        close: "true",
        delay: "6"
        });
</script>
<?php }
elseif (isset($addSuccess) && !$addSuccess) { ?>
<script type="text/javascript">
    $.notifyBar({
        html: "Something went wrong, please try again!",
        cls: "error",
        close: "true",
        delay: "6"
        });
</script>
<?php } ?>
<script type="text/javascript">
$(document).ready(function() {
    $("#addrep").validationEngine();
    $("#roles").change(function(){
        <?php if (isset($editRep)) { ?>$
            $("#mun_const").hide();
        <?php }?>
        url = '<?php echo base_url().'admin/representatives/ajaxGetMunicipalities/';?>';
        $.post (
        url,
        {
            role: $(this).val()
        },
        function(data){
            $("#municipality").html(data);
        });
    })
})
</script>
<form name="addrep" id="addrep" method="POST" action="<?php echo (isset($editRep) && $editRep)?base_url().'mk/admin/representatives/editrepresentative/'.$representative->rep_id:
                                                                                               base_url().'mk/admin/representatives/addrepresentative/';?>">
    <table class ="addrep">
        <tr id="role">
            <td>Role:</td>
            <td><?php //debug($representative)?>
                <select name = "roles" id = "roles" class="validate[required]">
                    <option value="0">Select</option>
                    
                    <option value="1" <?php if (isset($editRep) && $editRep && $representative->role_id == 1) echo 'selected = "selected"'?>>Pratenik</option>
                    <option value="2" <?php if (isset($editRep) && $editRep && $representative->role_id == 2) echo 'selected = "selected"'?>>Sovetnik</option>
                    <option value="3" <?php if (isset($editRep) && $editRep && $representative->role_id == 3) echo 'selected = "selected"'?>>Gradonacalnik</option>
                </select>
            </td>
        </tr>
        
        <tr name="municipality" id="municipality" class="validate[required]"><?php if (isset($mun_const_ddm)) print $mun_const_ddm;?></tr>
        <tr>
            <td>Name</td>
            <td><input name="firstname" id="firstname" class="validate[required]"
            <?php if (isset($editRep) && $editRep) echo 'value = "'.$representative->rep_name.'"';?>></td>
        </tr>
        <tr>
            <td>Lastname</td>
            <td><input name="lastname" id="lastname" class="validate[required]"
            <?php if (isset($editRep) && $editRep) echo 'value = "'.$representative->rep_surname.'"';?>></td>
        </tr>
        <tr>
            <td>email</td>
            <td><input name="email" id="email" class="validate[required]"
            <?php if (isset($editRep) && $editRep) echo 'value = "'.$representative->rep_email.'"';?>></td>
        </tr>
        <tr>
            <td></td>
            <td><button type="submit" name="addrep_btn">Add Representative</button></td>
        </tr>
    </table>
</form>